/**
 * Created by wanghao on 2018/08/30.
 */
import vue from "vue";
import vuex from "vuex";
import mutations from "./mutation";
import getters from "./getter";
import createPersistedState from "vuex-persistedstate";

vue.use(vuex);

const state = {
    user: false,
    // 对应状态
    statusList: [{ name: 0, value: "正常" }, { name: 1, value: "异常" }],
    // 所有设备类型
    equipmentType: [
        // id name(设备中文)；parent(所在页面)；enName(设备英文)；isOuter(是否内场设备);parentIndex(页面顺序，只要对应即可)
        // 交通控制
        { id: "4", name: "信号灯", parent: "交通控制设施", enName: "signalLights", isOuter: "1", parentIndex: 1 },
        { id: "1", name: "信号机", parent: "交通控制设施", enName: "signalMachines", isOuter: "1", parentIndex: 1 },
        // 交通信号方案
        { id: "18", name: "信号配时", parent: "交通信号方案", enName: "matchTimes", isOuter: "1", parentIndex: 2 },
        // 交通检测
        { id: "6", name: "微波", parent: "交通检测设备", enName: "microwaves", isOuter: "1", parentIndex: 3 },
        { id: "2", name: "地磁", parent: "交通检测设备", enName: "geomagneticSensors", isOuter: "1", parentIndex: 3 },
        // 电警监控设备
        { id: "3", name: "电子警察", parent: "电警监控设备", enName: "electronicPolices", isOuter: "1", parentIndex: 4 },
        { id: "11", name: "卡口", parent: "电警监控设备", enName: "dimentions", isOuter: "1", parentIndex: 4 },
        { id: "12", name: "违停", parent: "电警监控设备", enName: "illegalParkings", isOuter: "1", parentIndex: 4 },
        { id: "7", name: "视频监控", parent: "电警监控设备", enName: "monitors", isOuter: "1", parentIndex: 4 },
        // 交通诱导
        { id: "5", name: "诱导屏", parent: "交通诱导设备", enName: "induceScreens", isOuter: "1", parentIndex: 5 },
        // 机房设备
        { id: "14", name: "服务器", parent: "机房设备", enName: "servers", isOuter: "0", parentIndex: 6 },
        { id: "15", name: "交换机", parent: "机房设备", enName: "interchangers", isOuter: "0", parentIndex: 6 },
        { id: "19", name: "硬盘存储", parent: "机房设备", enName: "hardDiskStorages", isOuter: "0", parentIndex: 6 },
        { id: "20", name: "校时服务器", parent: "机房设备", enName: "timeoutserver", isOuter: "0", parentIndex: 6 },
        // 交通安全设备
        { id: "16", name: "标志", parent: "交通安全设备", enName: "symbols", isOuter: "1", parentIndex: 7 },
        { id: "17", name: "标线", parent: "交通安全设备", enName: "marks", isOuter: "1", parentIndex: 7 },
        { id: "13", name: "护栏", parent: "交通安全设备", enName: "fences", isOuter: "1", parentIndex: 7 }
    ],
    equipmentType2: [
        // id name(设备中文)；parent(所在页面)；enName(设备英文)；isOuter(是否内场设备);parentIndex(页面顺序，只要对应即可)
        // 交通控制
        {
            parent: "交通控制设施",
            parentIndex: 0,
            parentNmae: "trafficControlEquipment",
            equipmentTypeList: [
                { url: "01", id: "4", name: "信号灯", parent: "交通控制设施", enName: "signalLights", isOuter: "1", parentIndex: 0 },
                { url: "02", id: "1", name: "信号机", parent: "交通控制设施", enName: "signalMachines", isOuter: "1", parentIndex: 0 }
            ]
        },
        // 交通信号方案
        {
            parent: "交通信号设施",
            parentIndex: 1,
            parentNmae: "trafficSignalFacilities",
            equipmentTypeList: [
                { url: "11", id: "18", name: "信号配时", parent: "交通信号设施", enName: "matchTimes", isOuter: "1", parentIndex: 1 }
            ]
        },
        // 交通检测
        {
            parent: "交通检测设施",
            parentIndex: 2,
            parentNmae: "trafficSignalFacilities",
            equipmentTypeList: [
                { url: "21", id: "6", name: "微波", parent: "交通检测设施", enName: "microwaves", isOuter: "1", parentIndex: 2 },
                { url: "22", id: "2", name: "地磁", parent: "交通检测设施", enName: "geomagneticSensors", isOuter: "1", parentIndex: 2 }
            ]
        },
        // 电警监控设备
        {
            parent: "电警监控设施",
            parentIndex: 3,
            parentNmae: "trafficSignalFacilities",
            equipmentTypeList: [
                { url: "31", id: "3", name: "电子警察", parent: "电警监控设备", enName: "electronicPolices", isOuter: "1", parentIndex: 3 },
                { url: "32", id: "11", name: "卡口", parent: "电警监控设备", enName: "dimentions", isOuter: "1", parentIndex: 3 },
                { url: "33", id: "12", name: "违停", parent: "电警监控设备", enName: "illegalParkings", isOuter: "1", parentIndex: 3 },
                { url: "34", id: "7", name: "视频监控", parent: "电警监控设备", enName: "monitors", isOuter: "1", parentIndex: 3 }
            ]
        },
        // 交通诱导
        {
            parent: "交通诱导设施",
            parentIndex: 4,
            parentNmae: "trafficSignalFacilities",
            equipmentTypeList: [
                { url: "41", id: "5", name: "诱导屏", parent: "交通诱导设备", enName: "induceScreens", isOuter: "1", parentIndex: 4 }
            ]
        },
        // 机房设备
        {
            parent: "机房设施",
            parentIndex: 5,
            parentNmae: "trafficSignalFacilities",
            equipmentTypeList: [
                { url: "51", id: "14", name: "服务器", parent: "机房设备", enName: "servers", isOuter: "0", parentIndex: 5 },
                { url: "52", id: "15", name: "交换机", parent: "机房设备", enName: "interchangers", isOuter: "0", parentIndex: 5 },
                { url: "53", id: "19", name: "硬盘存储", parent: "机房设备", enName: "hardDiskStorages", isOuter: "0", parentIndex: 5 },
                { url: "54", id: "20", name: "校时服务器", parent: "机房设备", enName: "timeoutserver", isOuter: "0", parentIndex: 5 }
            ]
        },
        // 交通安全设备
        {
            parent: "交通安全设施",
            parentIndex: 6,
            parentNmae: "trafficSignalFacilities",
            equipmentTypeList: [
                { url: "61", id: "16", name: "标志", parent: "交通安全设备", enName: "symbols", isOuter: "1", parentIndex: 6 },
                { url: "62", id: "17", name: "标线", parent: "交通安全设备", enName: "marks", isOuter: "1", parentIndex: 6 },
                { url: "63", id: "13", name: "护栏", parent: "交通安全设备", enName: "fences", isOuter: "1", parentIndex: 6 }
            ]
        }
    ],
    count: 0,
    //  当前搜索结果
    resultArr: [],
    // websocket刷新
    boardRefresh: 0,
    mainRefresh: 0
};

const actions = {
    handlerSearch({ commit }, payload) {
        commit("getSearchArr", payload);
    },
    handlerCount({ commit }) {
        commit("setCount");
    }
};

const vuexPersisted = new createPersistedState({
    key: "state",
    storage: window.localStorage,
    modules: state
});
export default new vuex.Store({
    state,
    mutations,
    getters,
    actions,
    // plugins: [vuexPersisted],
    plugins: [vuexPersisted]
});
